package com.lmiot.xyclick.View;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.v4.internal.view.SupportMenu;
import android.util.AttributeSet;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;

public class SwipeView extends View {
    private static final String TAG = "PointView";
    private int mCententX0;
    private int mCententX1;
    private int mCententY0;
    private int mCententY1;
    private boolean mHasInsign0;
    private boolean mHasInsign1;
    private int mHeight;
    private Paint mPaint;
    private Paint mPaintLine;
    private int mPointAngle;
    private int mWidth;

    public SwipeView(Context context) {
        super(context);
    }

    public SwipeView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        Display defaultDisplay = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        this.mWidth = defaultDisplay.getWidth();
        this.mHeight = defaultDisplay.getHeight();
        Paint paint = new Paint();
        this.mPaint = paint;
        paint.setStyle(Paint.Style.FILL);
        this.mPaint.setColor(-65536);
        this.mPaint.setAntiAlias(true);
        Paint paint2 = new Paint();
        this.mPaintLine = paint2;
        paint2.setColor(-65536);
        this.mPaintLine.setStrokeWidth(20.0f);
        this.mPaintLine.setAntiAlias(true);
        int i = this.mWidth;
        this.mCententX0 = i / 8;
        int i2 = this.mHeight;
        this.mCententY0 = i2 / 2;
        this.mCententX1 = (i * 7) / 8;
        this.mCententY1 = i2 / 2;
    }

    /* access modifiers changed from: protected */
    public void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        boolean z = false;
        if (this.mCententX0 <= 0) {
            this.mCententX0 = 0;
        }
        int i = this.mCententX0;
        int i2 = this.mWidth;
        if (i >= i2) {
            this.mCententX0 = i2;
        }
        if (this.mCententY0 <= 0) {
            this.mCententY0 = 0;
        }
        int i3 = this.mCententY0;
        int i4 = this.mHeight;
        if (i3 >= i4) {
            this.mCententY0 = i4;
        }
        if (this.mCententX1 <= 0) {
            this.mCententX1 = 0;
        }
        if (this.mCententX1 >= i2) {
            this.mCententX1 = i2;
        }
        if (this.mCententY1 <= 0) {
            this.mCententY1 = 0;
        }
        if (this.mCententY1 >= i4) {
            this.mCententY1 = i4;
        }
        canvas.drawCircle((float) this.mCententX0, (float) this.mCententY0, 25.0f, this.mPaint);
        Path path = new Path();
        path.moveTo((float) this.mCententX1, (float) (this.mCententY1 - 30));
        path.lineTo((float) this.mCententX1, (float) (this.mCententY1 + 30));
        path.lineTo((float) (this.mCententX1 + 60), (float) this.mCententY1);
        path.close();
        float f = (float) (this.mCententX1 - this.mCententX0);
        float f2 = (float) (this.mCententY1 - this.mCententY0);
        int i5 = (f > 0.0f ? 1 : (f == 0.0f ? 0 : -1));
        int i6 = (f2 > 0.0f ? 1 : (f2 == 0.0f ? 0 : -1));
        if ((i5 <= 0) && (i6 >= 0)) {
            this.mPointAngle = (int) Math.toDegrees(Math.atan((double) ((f * -1.0f) / f2)));
        }
        int i7 = (f2 > 0.0f ? 1 : (f2 == 0.0f ? 0 : -1));
        if ((i5 <= 0) && (i7 <= 0)) {
            this.mPointAngle = ((int) Math.toDegrees(Math.atan((double) ((f2 * -1.0f) / (f * -1.0f))))) + 90;
        }
        int i8 = (f > 0.0f ? 1 : (f == 0.0f ? 0 : -1));
        if ((i8 >= 0) && (i7 <= 0)) {
            this.mPointAngle = ((int) Math.toDegrees(Math.atan((double) (f / (-1.0f * f2))))) + 180;
        }
        boolean z2 = i8 >= 0;
        if (i6 >= 0) {
            z = true;
        }
        if (z && z2) {
            this.mPointAngle = ((int) Math.toDegrees(Math.atan((double) (f2 / f)))) + SubsamplingScaleImageView.ORIENTATION_270;
        }
        canvas.drawLine((float) this.mCententX0, (float) this.mCententY0, (float) this.mCententX1, (float) this.mCententY1, this.mPaintLine);
        canvas.rotate((float) (this.mPointAngle + 90), (float) this.mCententX1, (float) this.mCententY1);
        canvas.drawPath(path, this.mPaint);
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        int action = motionEvent.getAction();
        if (action == 0) {
            int x = (int) motionEvent.getX();
            int y = (int) motionEvent.getY();
            int i = this.mCententX0;
            if (x >= i - 40 && x <= i + 40) {
                int i2 = this.mCententY0;
                if (y >= i2 - 40 && y <= i2 + 40) {
                    this.mHasInsign0 = true;
                }
            }
            int i3 = this.mCententX1;
            if (x >= i3 - 40 && x <= i3 + 40) {
                int i4 = this.mCententY1;
                if (y >= i4 - 40 && y <= i4 + 40) {
                    this.mHasInsign1 = true;
                }
            }
        } else if (action == 1) {
            this.mHasInsign0 = false;
            this.mHasInsign1 = false;
        } else if (action == 2) {
            if (this.mHasInsign0) {
                this.mCententX0 = (int) motionEvent.getX();
                this.mCententY0 = (int) motionEvent.getY();
                invalidate();
            }
            if (this.mHasInsign1) {
                this.mCententX1 = (int) motionEvent.getX();
                this.mCententY1 = (int) motionEvent.getY();
                invalidate();
            }
        }
        return true;
    }

    public void change(String str) {
        str.hashCode();
        char c = 65535;
        switch (str.hashCode()) {
            case 3739:
                if (str.equals("up")) {
                    c = 0;
                    break;
                }
                break;
            case 3089570:
                if (str.equals("down")) {
                    c = 1;
                    break;
                }
                break;
            case 3317767:
                if (str.equals("left")) {
                    c = 2;
                    break;
                }
                break;
            case 108511772:
                if (str.equals("right")) {
                    c = 3;
                    break;
                }
                break;
        }
        switch (c) {
            case 0:
                int i = this.mWidth;
                this.mCententX1 = i / 2;
                int i2 = this.mHeight;
                this.mCententY1 = i2 / 8;
                this.mCententX0 = i / 2;
                this.mCententY0 = (i2 * 7) / 8;
                break;
            case 1:
                int i3 = this.mWidth;
                this.mCententX0 = i3 / 2;
                int i4 = this.mHeight;
                this.mCententY0 = i4 / 8;
                this.mCententX1 = i3 / 2;
                this.mCententY1 = (i4 * 7) / 8;
                break;
            case 2:
                int i5 = this.mWidth;
                this.mCententX1 = i5 / 8;
                int i6 = this.mHeight;
                this.mCententY1 = i6 / 2;
                this.mCententX0 = (i5 * 7) / 8;
                this.mCententY0 = i6 / 2;
                break;
            case 3:
                int i7 = this.mWidth;
                this.mCententX0 = i7 / 8;
                int i8 = this.mHeight;
                this.mCententY0 = i8 / 2;
                this.mCententX1 = (i7 * 7) / 8;
                this.mCententY1 = i8 / 2;
                break;
        }
        invalidate();
    }

    public int getCententX0() {
        return this.mCententX0;
    }

    public int getCententY0() {
        return this.mCententY0;
    }

    public int getCententX1() {
        return this.mCententX1;
    }

    public int getCententY1() {
        return this.mCententY1;
    }
}
